package com.ecole.mines.emargement;

import android.app.Fragment;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ecole.mines.model.Cours;

public class FragmentDetailCours extends Fragment implements OnClickListener {

	private TextView detailNomCours, detailProf, detailSalle, detailDate,
			detailHeureDebut, detailHeureFin;
	private Button boutonAccesEmargement;
	private RelativeLayout relative;
	private Cours coursAffiche;
	private View rootView;

	public FragmentDetailCours() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = inflater.inflate(R.layout.fragment_detail, container, false);

		relative = (RelativeLayout) rootView.findViewById(R.id.detailCours);
		detailNomCours = (TextView) rootView.findViewById(R.id.detailNomCours);
		detailProf = (TextView) rootView.findViewById(R.id.detailNomProf);
		detailSalle = (TextView) rootView.findViewById(R.id.detailSalle);
		detailDate = (TextView) rootView.findViewById(R.id.detailDate);
		detailHeureDebut = (TextView) rootView
				.findViewById(R.id.detailHeureDebut);
		detailHeureFin = (TextView) rootView.findViewById(R.id.detailHeureFin);

		boutonAccesEmargement = (Button) rootView
				.findViewById(R.id.boutonAccesEmargement);
		boutonAccesEmargement.setOnClickListener(this);

		return rootView;
	}

	public void majDetailsCours() {
		if (this.rootView.getVisibility() == View.INVISIBLE) {
			this.rootView.setVisibility(View.VISIBLE);
		}
		detailNomCours.setText(coursAffiche.getNom());
		detailProf.setText(coursAffiche.getProf());
		detailSalle.setText(coursAffiche.getSalle());
		detailDate.setText(DateFormat.format("dd MMMM yyyy",
				coursAffiche.getDate()));
		detailHeureDebut.setText(DateFormat.format("kk",
				coursAffiche.getHeureDebut())
				+ "H" + DateFormat.format("mm", coursAffiche.getHeureDebut()));
		detailHeureFin.setText(DateFormat.format("kk",
				coursAffiche.getHeureFin())
				+ "H" + DateFormat.format("mm", coursAffiche.getHeureFin()));
		relative.setVisibility(View.VISIBLE);

	}

	@Override
	public void onClick(View v) {
		if (v == boutonAccesEmargement) {
			((MainActivity) getActivity()).demarreEmargementActivity();
		}
	}

	public void cacherVue() {
		this.rootView.setVisibility(View.INVISIBLE);
	}

	public Cours getCoursAffiche() {
		return coursAffiche;
	}

	public void setCoursAffiche(Cours coursAffiche) {
		this.coursAffiche = coursAffiche;
	}

}
